<template>
  <div class="homePage_container">
    <div class="header-div">
      <div class="top-div">
        <div class="logo-div"></div>
        <div class="nav-div">
          <div class="text-div">
            <span>
              <router-link to="/login" v-if="uUsername === ''">登录</router-link>
              <span class="username" v-else>{{ uUsername }}</span>
              &nbsp;&nbsp;|&nbsp;&nbsp;
              <router-link to="/register">注册</router-link>
            </span>
          </div>
          <div class="form-div">
            <form action="">
              <input type="search" placeholder="热门搜索: 干花花瓶" />
              <input type="button" />
            </form>
          </div>
          <div class="a-img-div">
            <router-link to="/grzx">
              <img src="@/assets/images/grzx.png" alt="无法加载图片" />
            </router-link>
            <router-link to="/gwc">
              <img src="@/assets/images/gwc.png" alt="无法加载图片" />
            </router-link>
          </div>
        </div>
      </div>
      <MyNav />
    </div>
    <!-- 走马灯 -->
    <div id="switch-div" class="switch">
      <el-carousel :interval="3000" trigger="click" height="720px">
        <el-carousel-item v-for="item in bannerList" :key="item.id">
          <img :src="item.swiperPic" alt="无法加载图片" />
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="main-series-div">
      <div class="parcel-div">
        <div><img src="@/assets/images/i1.jpg" alt="无法加载图片" /></div>
        <div><img src="@/assets/images/i2.jpg" alt="无法加载图片" /></div>
        <div><img src="@/assets/images/i3.jpg" alt="无法加载图片" /></div>
      </div>
    </div>
    <div class="title1-div">
      <img src="@/assets/images/tit01.jpg" alt="无法加载图片" />
    </div>
    <!-- 多肉植物系列 -->
    <div class="European-style">
      <div class="parcel-div">
        <div class="parcel-div" v-for="item in succulentList" :key="item.cmId">
          <a href="#" @click.prevent="goodsDetailInfo(item.cmId)">
            <span class="prefix"></span>
            <img :src="item.cmImg" alt="无法加载图片" />
            <span class="suffix"></span>
          </a>
          <div class="detail-div">
            <span>{{ item.cmName }}</span>
          </div>
          <div class="price-div">
            <span>￥{{ item.cmPrice }}0</span>
          </div>
        </div>
      </div>
    </div>
    <div class="title4-div">
      <img src="@/assets/images/tit04.jpg" alt="无法加载图片" />
    </div>
    <div class="Modern">
      <div class="parcel-div">
        <div class="parcel-div">
          <router-link to="/goodDetail">
            <img src="@/assets/images/modern1.jpg" alt="" />
          </router-link>
          <div class="detail-div"><span>【最家】美丽仿真花束</span></div>
          <div class="price-div"><span>￥49.90</span></div>
        </div>
        <div class="parcel-div">
          <router-link to="/goodDetail">
            <img src="@/assets/images/modern5.jpg" alt="" />
          </router-link>
          <div class="detail-div"><span>【最家】美丽仿真花束</span></div>
          <div class="price-div"><span>￥49.90</span></div>
        </div>
        <div class="parcel-div">
          <router-link to="/goodDetail">
            <img src="@/assets/images/modern6.jpg" alt="" />
          </router-link>
          <div class="detail-div"><span>【最家】美丽仿真花束</span></div>
          <div class="price-div"><span>￥49.90</span></div>
        </div>
        <div class="parcel-div">
          <router-link to="/goodDetail">
            <img src="@/assets/images/modern7.jpg" alt="" />
          </router-link>
          <div class="detail-div"><span>【最家】美丽仿真花束</span></div>
          <div class="price-div"><span>￥49.90</span></div>
        </div>
        <div class="parcel-div">
          <router-link to="/goodDetail">
            <img src="@/assets/images/modern2.jpg" alt="" />
          </router-link>
          <div class="detail-div"><span>【最家】美丽仿真花束</span></div>
          <div class="price-div"><span>￥49.90</span></div>
        </div>
        <div class="parcel-div">
          <router-link to="/goodDetail">
            <img src="@/assets/images/modern3.jpg" alt="" />
          </router-link>
          <div class="detail-div"><span>【最家】美丽仿真花束</span></div>
          <div class="price-div"><span>￥49.90</span></div>
        </div>
        <div class="parcel-div">
          <router-link to="/goodDetail">
            <img src="@/assets/images/modern4.jpg" alt="" />
          </router-link>
          <div class="detail-div"><span>【最家】美丽仿真花束</span></div>
          <div class="price-div"><span>￥49.90</span></div>
        </div>
        <div class="parcel-div">
          <router-link to="/goodDetail">
            <img src="@/assets/images/modern8.jpg" alt="" />
          </router-link>
          <div class="detail-div"><span>【最家】美丽仿真花束</span></div>
          <div class="price-div"><span>￥49.90</span></div>
        </div>
      </div>
    </div>
    <div class="xx-title-div">
      <img src="@/assets/images/hyB01.jpg" alt="无法加载图片" />
    </div>
    <!-- 仿真花系列 -->
    <div class="xiangxun">
      <div class="parcel-div">
        <div class="parcel-div" v-for="item in artificialList" :key="item.cmId">
          <a href="#" @click.prevent="goodsDetailInfo(item.cmId)">
            <span class="prefix"></span>
            <img :src="item.cmImg" alt="无法加载图片" />
            <span class="suffix"></span>
          </a>
          <div class="detail-div">
            <span>{{ item.cmName }}</span>
          </div>
          <div class="price-div">
            <span>￥{{ item.cmPrice }}0</span>
          </div>
        </div>
      </div>
    </div>
    <MyFooter />
    <MyBroad />
  </div>
</template>

<script>
import MyFooter from '@/components/common/MyFooter.vue'
import MyNav from '@/components/common/MyNav.vue'
import MyBroad from '@/components/common/MyBroad.vue'
export default {
  name: 'homePage',
  data() {
    return {
      uUsername: '',
      bannerList: [],
      succulentList: [],
      artificialList: []
    }
  },
  created() {
    this.getUserInfo()
    this.getSwiperList()
    this.getCommodityList()
  },
  methods: {
    getUserInfo() {
      this.$http
        .get('/user/me')
        .then(res => {
          if (res.state === false) {
            return
          }
          this.uUsername = res.data.uUsername
          window.localStorage.setItem('userId', res.data.uId)
          this.$message.success('欢迎回来 ' + (res.data.uSex === '男' ? 'Mr. ' : 'Ms. ') + res.data.uUsername)
        })
        .catch(err => this.$message.error(err))
    },
    getSwiperList() {
      this.$http
        .get('/swiper/allSwiper')
        .then(res => {
          this.bannerList = res.data
        })
        .catch(err => this.$message.error(err))
    },
    getCommodityList() {
      this.$http
        .get('/commodity/succulentList')
        .then(res => {
          this.succulentList = res.data
        })
        .catch(err => this.$message.error(err))
      this.$http
        .get('/commodity/artificialList')
        .then(res => {
          this.artificialList = res.data
        })
        .catch(err => this.$message.error(err))
    },
    goodsDetailInfo(id) {
      this.$router.push('/goodDetail/' + id)
    }
  },
  components: {
    MyFooter,
    MyNav,
    MyBroad
  }
}
</script>

<style lang="less" scoped>
/********************* 全局配置 *********************/
.homePage_container {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  position: absolute;
}

/********************* header *********************/
.header-div {
  .top-div::after {
    content: '';
    clear: both;
    display: block;
  }
  .top-div .logo-div {
    float: left;
    width: 400px;
    height: 140px;
    background-size: 35%;
    background-position: center;
    background-repeat: no-repeat;
    background-image: url('@/assets/images/logo.png');
  }
  .top-div .nav-div {
    float: right;
    display: flex;
    padding: 70px 50px 0px;
  }
  .top-div .text-div {
    font-size: 20px;
    padding: 0 20px;
    line-height: 50px;
    text-align: center;
    color: rgba(0, 0, 0, 0.7);
  }
  .top-div form {
    display: flex;
    border-bottom: 1px solid rgba(0, 0, 0, 0.8);
  }
  .top-div form input:first-child {
    width: 80%;
    border: none;
    height: 2.5em;
    outline: none;
    font-size: 20px;
    background-size: 25px;
    padding: 5px 0px 5px 10px;
  }
  .top-div form input:last-child {
    width: 20%;
    border: none;
    cursor: pointer;
    background-color: #fff;
    background-position: center;
    background-repeat: no-repeat;
    background-size: 50%;
    background-image: url('@/assets/images/ss.png');
  }
  .top-div .a-img-div {
    display: flex;
    padding: 0 20px;
    position: relative;
    align-items: center;
    justify-content: center;
  }
  .top-div .a-img-div a {
    margin: 0 10px;
  }
  .top-div .a-img-div a img {
    width: 1.5em;
  }
}

/********************* 主页下拉框 *********************/
.dropdown-content-one {
  left: 0;
  top: 50px;
  z-index: 2;
  width: 100%;
  display: none;
  padding: 20px 0;
  position: absolute;
  background-color: #fff;
  border-top: 2px solid #dbdbdb;
  box-shadow: inset 0px -16px 16px 0px rgba(0, 0, 0, 0.2);
  .wrapper {
    width: 70%;
    display: flex;
    margin: 0 auto;
    justify-content: center;
    a {
      padding: 0 20px;
      display: inline-block;
      border-right: 2px solid #dbdbdb;
    }
    a:last-child {
      border-right: none;
    }
  }
  .img-div-one {
    line-height: 0;
    img {
      width: 100%;
    }
  }
}

.dropdown-text-div {
  font-size: 20px;
  line-height: 40px;
}

/********************* footer *********************/
.switch img {
  height: 720px;
}

/********************* main-series *********************/
.main-series-div {
  display: flex;
  position: relative;
  justify-content: center;
  .parcel-div {
    top: -100px;
    z-index: 999;
    width: 820px;
    font-size: 0;
    display: flex;
    padding: 20px;
    position: absolute;
    border: 2px solid #dbdbdb;
    justify-content: space-between;
    background: url('@/assets/images/bg.jpg') #fff repeat-x bottom;
  }
  .parcel-div div {
    overflow: hidden;
  }
  .parcel-div div img {
    cursor: pointer;
    transition: all 1.5s ease;
  }
  .parcel-div div:hover img {
    transform: scale(1.1, 1.1);
  }
}

.main-series-div::after {
  content: '';
  clear: both;
  height: 290px;
  display: block;
}

.title1-div,
.title4-div {
  padding: 20px 0;
  text-align: center;
}

/********************* European *********************/
.European-style,
.Modern,
.xiangxun {
  display: flex;
  justify-content: center;
}

.European-style {
  img {
    width: 356px;
  }
  > .parcel-div {
    width: 1100px;
    display: flex;
    flex-flow: row wrap;
  }
  > .parcel-div .parcel-div {
    flex: 0 0 30%;
    margin: 0 5px 40px;
  }
  > .parcel-div .parcel-div {
    flex: 0 0 30%;
    margin: 0 5px 40px;
  }
  a {
    font-size: 0;
    display: block;
    overflow: hidden;
    position: relative;
  }
  a:hover span {
    top: 0;
    left: 0;
    transition: all 0.5s ease;
  }
  a .prefix {
    top: -100%;
    left: -100%;
    width: 100%;
    height: 100%;
    opacity: 0.2;
    position: absolute;
    background-color: #90d7ec;
  }
  a .suffix {
    top: 100%;
    left: 100%;
    width: 100%;
    height: 100%;
    opacity: 0.2;
    position: absolute;
    background-color: #90d7ec;
  }
  .detail-div {
    text-align: center;
  }
  .detail-div span {
    line-height: 60px;
    user-select: none;
    color: rgba(0, 0, 0, 0.7);
  }
  .price-div {
    display: flex;
    justify-content: center;
  }
  .price-div span {
    padding: 10px;
    font-size: 14px;
    color: #a10000;
    user-select: none;
    font-weight: bold;
    transition: all 0.5s ease;
    border: 1px solid rgba(0, 0, 0, 0.5);
  }
  .price-div span:hover {
    color: #fff;
    background-color: #a10000;
  }
}

/********************* Modern *********************/
.Modern {
  > .parcel-div {
    width: 1200px;
    display: flex;
    flex-flow: row wrap;
  }
  a {
    font-size: 0;
    display: block;
  }
  img {
    width: 288px;
    height: 288px;
  }
  > .parcel-div .parcel-div {
    flex: 0 0 20%;
    margin: 0 6px 40px;
    padding-bottom: 10px;
  }
  > .parcel-div .parcel-div:hover {
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.8);
  }
  .parcel-div > a {
    transition: all 1s ease;
  }
  .parcel-div > a:hover {
    opacity: 0.6;
  }
  .detail-div {
    text-align: center;
  }
  .detail-div span {
    font-size: 16px;
    line-height: 50px;
    color: rgba(0, 0, 0, 0.7);
  }
  .price-div {
    display: flex;
    justify-content: center;
  }
  .price-div span {
    padding: 10px;
    font-size: 14px;
    color: #a10000;
    user-select: none;
    font-weight: bold;
    transition: all 0.5s ease;
    border: 1px solid rgba(0, 0, 0, 0.5);
  }
  .price-div span:hover {
    color: #fff;
    background-color: #a10000;
  }
}

.xx-title-div {
  font-size: 0;
  text-align: center;
  padding-bottom: 20px;
  img {
    width: 1250px;
    height: 450px;
  }
}

/********************* xiangxun *********************/
.xiangxun {
  img {
    width: 374px;
    height: 374px;
    transition: all 1s ease;
  }
  a {
    font-size: 0;
    display: block;
    overflow: hidden;
    position: relative;
  }
  > .parcel-div {
    width: 1200px;
    display: flex;
    flex-flow: row wrap;
  }
  > .parcel-div .parcel-div {
    flex: 0 0 30%;
    margin: 0 13px 40px;
  }
  .detail-div,
  .price-div {
    font-size: 14px;
    user-select: none;
  }
  .detail-div {
    line-height: 30px;
    color: rgba(0, 0, 0, 0.7);
  }
  .price-div {
    color: #a10000;
  }
  > .parcel-div .parcel-div:hover {
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.8);
  }
  .prefix {
    top: 20px;
    left: 20px;
    z-index: 1;
    width: 344px;
    height: 344px;
    position: absolute;
    transform: scaleX(0);
    transition: all 0.5s ease;
    transform-origin: left top;
    border-top: 2px solid #90d7ec;
    border-left: 2px solid #90d7ec;
  }
  > .parcel-div .parcel-div:hover .prefix {
    transform: scaleX(1);
  }
  .suffix {
    z-index: 1;
    right: 20px;
    bottom: 20px;
    width: 344px;
    height: 344px;
    position: absolute;
    transform: scaleY(0);
    transition: all 0.5s ease;
    transform-origin: right bottom;
    border-right: 2px solid #90d7ec;
    border-bottom: 2px solid #90d7ec;
  }
  > .parcel-div .parcel-div:hover .suffix {
    transform: scaleY(1);
  }
  > .parcel-div .parcel-div:hover img {
    transform: scale(1.1, 1.1);
  }
}
</style>
